const http = require('http');

const server = http.createServer();

server.on('request', (req,res) => {
    const url = req.url;
    let content = "<h4>404 not found</h4>";
    if (url == "/" || url == "/index.html") {
        content = "<h4>首页哦</h4>";
    } else if (url == "/about.html") {
        content = "有关页面哈哈哈哈";
    }

    // 防止中文乱码
    res.setHeader("Content-Type", "text/html;charset=utf-8");
    // res.end() 把内容相应到客户端
    res.end(content);
});

server.listen(8080, () => {
    console.log(`服务器开启, 127.0.0.1:8080`);
});

